// pages/user-hyzx-xgmm/user-hyzx-xgmm.js
var util = require('../../utils/network.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
      message:'',
      bShow:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      
     
  },
  formSubmit:function(e){
        var that = this
        var userInfo = JSON.parse(wx.getStorageSync('userInfo'))
        var token = util.token
        var password = e.detail.value.oldpwd
        var newpassword = e.detail.value.newpwd
        var confirmpassword = e.detail.value.confirmpassword
        if (password != '' & newpassword != '' & confirmpassword!=''){
            if (newpassword == confirmpassword){
                wx.request({
                    url: util.main + '/user/updatepassword',
                    data: {
                        "user.id": userInfo.id,
                        "user.username": userInfo.realname,
                        "user.password": password,
                        "user.newpassword": newpassword,
                        "user.confirmpassword": confirmpassword,
                        "deviceid": wx.getStorageSync('openId'),
                        "token": token
                    },
                    header: {
                        "content-type": "application/x-www-form-urlencoded",
                        "accept": "application/json,",
                    },
                    method: "POST",
                    dataType: "json",
                    success: function (res) {
                        if (res.statusCode!=200){
                            that.setData({
                                message: res.data[0].message,
                                bShow: !that.data.bShow
                            })
                            if (that.data.bShow) {
                                setTimeout(function () {
                                    that.setData({
                                        bShow: !that.data.bShow
                                    })
                                }, 3000)
                            }
                        }
                        console.log(res)

                    }
                })
            }else{
                that.setData({
                    message:'两次密码不一致，请重新输入',
                    bShow: !that.data.bShow
                })
            }
        }else{
            that.setData({
                message: '请将信息补充完整',
                bShow: !that.data.bShow
            })
        }
        if (that.data.bShow) {
            setTimeout(function () {
                that.setData({
                    bShow: !that.data.bShow
                })
            }, 3000)
        }
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})